package pl.ydp.components.mathcell.mathrecognizer.geometry.classification
{
	import pl.ydp.components.mathcell.mathrecognizer.geometry.classification.CurveType;
	
	public class PrimitiveSubstanceType
	{
		
		public static const UNKNOWN:Number = 1; 
		
		private static const POSITIVE:Number = 2;
		private static const NEGATIVE:Number = 4;
		
		public static const DOT:Number = 64;
		public static const LINE:Number = 128;
		private static const CURVE:Number = 256;
		private static const WAVE:Number = 512;
		private static const HELIX:Number = 1024;
		private static const LOOP:Number = 2048;
		public static const FLOURISH:Number = 4096;
		
		public static const CURVE_POSITIVE:Number = CURVE | POSITIVE;
		public static const CURVE_NEGATIVE:Number = CURVE | NEGATIVE;
		
		
		public static const LOOP_POSITIVE:Number = LOOP | POSITIVE;
		public static const LOOP_NEGATIVE:Number = LOOP | NEGATIVE;
		
		//--------------------------------------------------------
		
		public static function isLine(_ptt:Number):Boolean{
			return (((_ptt & LINE) != 0)  ||  ((_ptt & WAVE) != 0));
		}
		
		//--------------------------------------------------------
		
		public static function isCurve(_ptt:Number):Boolean{
			return ((_ptt & CURVE) != 0);
		}
		
		//--------------------------------------------------------
		
		public static function isWave(_ptt:Number):Boolean{
			return ((_ptt & WAVE) != 0);
		}
		
		//--------------------------------------------------------
		
		public static function isHelix(_ptt:Number):Boolean{
			return ((_ptt & HELIX) != 0);
		}
		
		//--------------------------------------------------------
		
		public static function isLoop(_ptt:Number):Boolean{
			return ((_ptt & LOOP) != 0);
		}
		//--------------------------------------------------------
		
		public static function isFlourish(_ptt:Number):Boolean{
			return ((_ptt & FLOURISH) != 0);
		}
		
		//--------------------------------------------------------
		
		public static function fromGeneralType(_generalType:Number, _curveType:Number = 0):Number{
			
			var output:Number = 0;
			
			if (_generalType == PrimitiveGeneralType.NONE){
				return UNKNOWN;
			} else if (_generalType == PrimitiveGeneralType.DOT){
				return DOT;
			} else if (_generalType == PrimitiveGeneralType.LINE){
				return LINE;
			} else if (_generalType == PrimitiveGeneralType.CURVE){
				output |= CURVE;
			} else if (_generalType == PrimitiveGeneralType.WAVE){
				return WAVE;
			} else if (_generalType == PrimitiveGeneralType.LOOP){
				output |= LOOP;
			}  else if (_generalType == PrimitiveGeneralType.FLOURISH){
				return FLOURISH;
			} else {
				return UNKNOWN;
			}

			if (_curveType == CurveType.POSITIVE){
				output |= POSITIVE;
			} else if (_curveType == CurveType.NEGATIVE){
				output |= NEGATIVE;
			} else {
				return UNKNOWN;
			}
			
			return output;
		}
		
		//--------------------------------------------------------
		
		public static function fromPrimitiveType(_primitiveType:Number):Number{
			
			var output:Number;
			
			if (_primitiveType & PrimitiveType.LOOP){
				return PrimitiveSubstanceType.LOOP_POSITIVE;
			} else if (_primitiveType & PrimitiveType.CURVE){
				return PrimitiveSubstanceType.CURVE_POSITIVE;
			} else if (_primitiveType & PrimitiveType.WAVE){
				return PrimitiveSubstanceType.WAVE;
			} else if (_primitiveType & PrimitiveType.LINE){
				return PrimitiveSubstanceType.LINE;
			}
			
			return output;
		}
	}
}